//
//  CartProdItemFrame.m
//  JiaoX
//
//  Created by jiaoxiu－005 on 15/1/13.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "CartProdItemFrame.h"
#import "CartProdSub.h"
#import "CalcView.h"



@implementation CartProdItemFrame
-(void)setInfos:(CartProdSub *)infos{
    _infos = infos;
    // 1.商品图片
    CGFloat iconX = JXPublicInset;
    CGFloat iconY = JXPublicInset;
    CGFloat iconW = PRODUCT_ICON_SIZE_W;
    CGFloat iconH = PRODUCT_ICON_SIZE_H;
    self.iconFrame = CGRectMake(iconX, iconY, iconW, iconH);
 
    // 2.商品名称
    CGFloat nameX = CGRectGetMaxX(self.iconFrame) + JXPublicInset;
    CGFloat nameY = iconY;
    CGSize nameSize = [infos.prodName sizeWithFont:[UIFont systemFontOfSize:PRODUCT_NAME_SIZE]constrainedToSize:CGSizeMake(JXScreenW-CGRectGetMaxX(self.iconFrame)-JXPublicInset*2, [UIFont systemFontOfSize:PRODUCT_NAME_SIZE].lineHeight * 4)];
    self.nameFrame = (CGRect){{nameX, nameY}, nameSize};
    
    //4.价格
    CGFloat priceX = nameX;
    CGFloat priceY = CGRectGetMaxY(self.iconFrame) - JXPublicInset - [UIFont systemFontOfSize:PRODUCT_PRICE_SIZE].lineHeight;
    NSString *dor = @"￥";
    dor = [dor stringByAppendingString:infos.prodNewPrice];
    CGSize priceSize = [dor sizeWithFont:[UIFont systemFontOfSize:PRODUCT_PRICE_SIZE]];
    self.priceFrame = (CGRect){{priceX, priceY}, priceSize};
    
    //5.计算器
//    CGFloat calcX = JXScreenW-97-10;
    CGFloat calcY = priceY-2.5;
//    self.calcX = calcX;
    self.calcY = calcY;
    
    //3.订购链接
    CGFloat skuX = nameX;
    CGFloat skuY = CGRectGetMaxY(self.nameFrame)+((self.calcY-CGRectGetMaxY(self.nameFrame)-[UIFont systemFontOfSize:PRODUCT_SKU_SIZE].lineHeight)/2);
    CGSize skuSize = [infos.prodBuyLink sizeWithFont:[UIFont systemFontOfSize:PRODUCT_SKU_SIZE]];
    self.skuFrame = (CGRect){{skuX, skuY}, skuSize};
    
    CGFloat h = 0;
    ProdPromotion *prodPromotion =  infos.prodPromotion;
    if(prodPromotion){
        if(prodPromotion.presentList.count>0){//有赠品
            //6.赠品
            CGFloat presentX = JXPublicInset;
            CGFloat presentY = CGRectGetMaxY(self.iconFrame)+JXPublicInset;
            self.presentFrameX = presentX;
            self.presentFrameY = presentY;
            h = presentY+[UIFont systemFontOfSize:PRODUCT_PRESENT_SIZE].lineHeight+JXPublicInset;
            //7.抢购价
            if(prodPromotion.price){//有抢购价
                CGFloat salesX = JXPublicInset;
                CGFloat salesY = self.presentFrameY+JXPublicInset*2;
                self.salesFrameX  = salesX;
                self.salesFrameY = salesY;
                h = salesY+[UIFont systemFontOfSize:PRODUCT_PRESENT_SIZE].lineHeight+JXPublicInset;
            }
        }else {
            if(prodPromotion.price){//有抢购价
                CGFloat salesX = JXPublicInset;
                CGFloat salesY =  CGRectGetMaxY(self.iconFrame)+JXPublicInset;
                self.salesFrameX  = salesX;
                self.salesFrameY = salesY;
                h = salesY+ [UIFont systemFontOfSize:PRODUCT_PRESENT_SIZE].lineHeight + JXPublicInset;
            }
        }
    }else{
        h = CGRectGetMaxY(self.iconFrame) + JXPublicInset;
    }
    // 自己
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = JXScreenW;
    self.frame = CGRectMake(x, y, w, h);
}

@end
